<template>
    <fieldset>
        <legend>登入页</legend>
        用户名：
        <input type="text" v-model="username">
        <br>
        密码：
        <input type="text" v-model="password" @keydown.enter="login">
        <button @click="login">登入</button>
    </fieldset>
</template>
<script setup>
import {ref} from "vue"
import * as api from "../../api/index"
import {useRouter} from "vue-router"
let username=ref("")
let password=ref("")

let router=useRouter()

let login=async()=>{
   let res=await api.loginApi(username.value,password.value)

    if(res.data.state){
    sessionStorage.setItem('token',res.data.token)
    router.push("/")
    }else{
        alert(res.data.msg)
    }
   console.log(res);
}
</script>